package com.qf.dao.impl;

import com.qf.dao.EmpDao;

import com.qf.pojo.Emp;
import com.qf.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class EmpDaoImpl implements EmpDao {
    QueryRunner qr =new QueryRunner(DataSourceUtil.getDataSource());



    @Override
    public List<Emp> findEmplist(String teamId) {
        String sql = "select * from emp where team_id=?";
        try {
            return qr.query(sql,new BeanListHandler<>(Emp.class),teamId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Emp findEmpName(int empId) {
        String sql="select * from emp where emp_id=?";
        try {
            return qr.query(sql,new BeanHandler<>(Emp.class),empId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
